function generate_list_cont(list_col_name_arr, list_col_size_arr, thclass_arr) {
  var search_list_thead='';
  for (var i = 0; i < list_col_name_arr.length; ++i) {
    var th = '<div style="width:'
      + list_col_size_arr[i] + '" '
      + 'class="' + thclass_arr[i] + '">'
      + list_col_name_arr[i] + '</div>';
    search_list_thead += th;
  }
  return search_list_thead;
};

function LoadSearchingResult() {
  $.ajax({
    url: searchresult_url + '/?' + GetUrlParams(),
    type: 'GET',
    dataType: 'text',
    timeout: 10000,
    error: function(){
      alert('Error loading XML document');
    },
    success: function(HTML){
      var search_result_num = $(HTML).find('.searchresult').size();
      var search_result_name = $(HTML).find('.searchresultname').text();
      var search_keywords = $(HTML).find('.searchkeywords').text();
      
      // Add search title.
      var search_result_title = '<h2>'
                                + search_result_num
                                + ' ' + search_result_name
                                + ' Match'
                                + ' for "' + search_keywords
                                + '"</h2>';
      var bar_line = '<div style="border-bottom:2px solid #ccc; height:7px"></div>';
      $(search_result_title).appendTo('#SearchResultTitle');
      $(bar_line).appendTo('#SearchResultTitle');
      if (search_result_num > 0)
      {
        // Add seatch list table column name.
        var search_result_list_head = generate_list_cont(
          list_col_name, list_col_size,
          ['SearchResultLHeadclass','SearchResultLHeadclass','SearchResultLHeadclass']);
        $(search_result_list_head).appendTo('#SearchResultListHead');

        $(HTML).find('.searchresult').each(function() {
          // Add search list items.
          var item_arr = new Array();
          for (var i = 0; i < list_col_size.length; ++i) {
            item_arr.push($(this).find('.col' + i).html());
          }

          var one_row_to_search_list = generate_list_cont(
            item_arr, list_col_size,
            ['SearchResultLItemclass_1', 'SearchResultLItemclass_2', 'SearchResultLItemclass_2']);
          $(one_row_to_search_list).appendTo('#SearchResultListItems');
          });
      }
    }
  });
}

$(function() {
    $('#search_result_block').css('display', 'none');
    $('#search_group').click(function(){
      $('#search_result_block').hide('fast');
      $('#SearchResultTitle').empty();
      $('#SearchResultListHead').empty();
      $('#SearchResultListItems').empty();
      $('#search_result_block').show('fast');
      LoadSearchingResult();
      });
});
